﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TracedReality.Logging
{
    /// <summary>
    /// Used for application wide logging.
    /// </summary>
    public class Log
    {
        /// <summary>
        /// The receivers that get whatever is logged.
        /// </summary>
        private static List<LogReceiver> receivers = new List<LogReceiver>();

        /// <summary>
        /// Add a receiver to the list of receivers.
        /// </summary>
        /// <param name="lr">Receiver to add.</param>
        public static void addReceiver(LogReceiver lr) { receivers.Add(lr); }

        /// <summary>
        /// Log a string.
        /// </summary>
        /// <param name="str">String to log.</param>
        public static void log(string str)
        {
            foreach (LogReceiver lo in receivers) { lo.giveString(str); }
        }

        /// <summary>
        /// Log an object.
        /// Calls ToString on the object if it is not null.
        /// </summary>
        /// <param name="obj">Object to log.</param>
        public static void log(object obj) { if (obj != null) { log(obj.ToString()); } }
    }
}
